package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.mapper.ParamMetricsMapper;
import com.zhentao.pojo.ParamMetrics;
import com.zhentao.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "参数监控", description = "参数监控指标接口")
@RestController
@RequestMapping("/param/metrics")
@RequiredArgsConstructor
public class ParamMetricsController {

    private final ParamMetricsMapper metricsMapper;

    @Operation(summary = "分页查询指标")
    @GetMapping("/page")
    public Result page(Integer pageNum, Integer pageSize, Long paramId) {
        Page<ParamMetrics> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        LambdaQueryWrapper<ParamMetrics> wrapper = new LambdaQueryWrapper<>();
        if (paramId != null) wrapper.eq(ParamMetrics::getParamId, paramId);
        wrapper.orderByDesc(ParamMetrics::getMetricDate);
        return Result.OK(metricsMapper.selectPage(page, wrapper));
    }
}


